<?php

namespace App\Admin\Controllers;

class TopicController extends Controller{
   // 专题列表页
    public function index(){
        $topics = \App\Topic::paginate(5);
        return view('admin.topic.index',compact('topics'));
    }
    // 创建专题
    public function create(){
        return view('admin.topic.add');
    }
    // 创建行为
    public function store(){
        $this->validate(request(),[
            'name' => 'required|min:2',
        ]);
        \App\Topic::create(['name' => request('name')]);
        return redirect('/admin/topics');
    }
    // 删除专题
    public function destroy(\App\Topic $topic){
        $topic->delete();
        return [
            'status'=> 0,
            'msg' =>'专题删除成功!',
        ];
    }
}